package com.webiatech.server.uploadfile;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;




/**
 * Servlet implementation class TestByteArrServlet
 */

public class TestByteArrServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static int fileNumber = 1;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TestByteArrServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html");
		String fileName = request.getParameter("qqfile");
		
		java.io.ByteArrayOutputStream bos = ByteExtractor.extractBytes(request);
		/*
		try
		{
			File f = new File("C:\\temp\\"+fileName);
			FileOutputStream fos = new FileOutputStream(f);
			bos.writeTo(fos);
			fos.flush();
			fos.close();
		}
		catch (IOException ex)
		{
			ex.printStackTrace();
		}
		
		*/
		
		/*
        FileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);
        List<FileItem> items = null;
        try {
            items = upload.parseRequest(request);
 
            for (FileItem item : items) {
                if (!item.isFormField()) {
                    String fileName = item.getName();
                    File f = new File("C:\\temp\\" + fileName);
                    item.write(f);
                }
            }
 
        } catch (FileUploadException e) {
            e.printStackTrace();
        } catch (Exception ex) {
        	ex.printStackTrace();
        }*/
		response.getWriter().write("{success:true,filePath:\"c:/temp/"+fileName+"\"}");
	}

}
